package models;

import java.util.*;
import play.data.validation.Constraints.*;
import play.db.ebean.*;
import javax.persistence.*;

@Entity
public class Stop extends Model {
    
    @Id
    public String stopId;
    public String stopCode; /* not used */
    @Required
    public String stopName;
    public String stopDesc; /* not used */
    public String platformCode;
    @Required
    public double latitude;
    @Required
    public double longitude;
    public String zoneId;  /* not used */
    public String stopUrl; /* not used */
    public int locationType;
    public String parentStation;
    
    public static Finder<String,Stop> find = new Finder(
        String.class, Stop.class
    );
    
    public Stop() { }
    
    public Stop(String stopId, String stopName, double latitude, double longitude) {
        this.stopId = stopId;
        this.stopName = stopName;
        this.latitude = latitude;
        this.longitude = longitude;
    }
    

    
    public static Stop getById(String stopId) {
        Stop stop = Stop.find.byId(stopId);
        return stop;
    }
    
    public static Stop getByName(String stopName)
    {
        //TODO exceptions
        List<Stop> stops = Stop.find
                        .where().like("stop_name", "%" + stopName + "%")
                        .findList();
        Stop stop = stops.get(0);
        if (stop != null) {
            return stop;
        } else {
            return null;
        }
    }
    
}